<?php

/**
 * Application user identity class
 *
 * Object of this class will be always returned by Zend_Auth::getInstance()->getIdentity();
 * It may be admin or guest
 */
class Application_Auth_User implements Zend_Acl_Role_Interface
{
    private $_userRow = null;
    private $_authToken = null;

    /**
     * @param string $authToken
     * @param Zend_Db_Table_Row_Abstract $userRow
     */
    public function __construct($authToken, Zend_Db_Table_Row_Abstract $userRow = null)
    {
        $this->_userRow = $userRow;
        $this->_authToken = $authToken;
    }

    /**
     * Whether user is logged in as admin or not (so user is guest).
     *
     * Needed for example to check if login form should be rendered for this user.
     *
     * @return boolean
     */
    public function isLoggedIn()
    {
        return !is_null($this->_userRow);
    }

    /**
     * @return string
     */
    public function getUsername()
    {
        return $this->isLoggedIn() ? $this->_userRow->username : 'guest';
    }

    /**
     * @return string
     */
    public function getAuthToken()
    {
        return $this->_authToken;
    }

    /**
     * @return string
     */
    public function getRoleId()
    {
        return $this->isLoggedIn() ? 'admin' : 'guest';
    }
}